home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
comm2
/
termsorc.lha
/
Extras
/
Source
/
gtlayout-source.lha
/
LTP_ConvertNum.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-24
|
1KB
|
97 lines
/* GadTools layout toolkit
**
** Copyright © 1993-1995 by Olaf `Olsen' Barthel
** Freely distributable.
*/
#include "gtlayout_global.h"
#ifdef DO_HEXHOOK
// Check whether the buffer only contains a valid hex/binary/octal number...
BOOLEAN __regargs
LTP_ConvertNum(BOOLEAN negAllowed,STRPTR buffer,LONG *value)
{
UBYTE ch;
ULONG num;
LONG neg;
num = 0;
if((buffer[0] == '-') && negAllowed)
{
neg = -1;
buffer++;
}
else
neg = 1;
if(((buffer[0] == '0') && ToUpper(buffer[1] == 'X')) || (buffer[0] == '$'))
{
if(*buffer++ != '$')
buffer++;
while(ch = ToUpper(*buffer++))
{
num = num * 16;
if((ch >= 'A') && (ch <= 'F'))
num += (ch & 0xF) + 9;
else
{
if ((ch >= '0') && (ch <= '9'))
num += ch & 0xF;
else
return(FALSE);
}
}
}
else
{
if(*buffer == '%')
{
buffer++;
while(ch = *buffer++)
{
if((ch < '0') || (ch > '1'))
return(FALSE);
num = (num * 2) + (ch & 0xF);
}
}
else
{
if(*buffer == '&')
{
buffer++;
while(ch = *buffer++)
{
if((ch < '0') || (ch > '7'))
return(FALSE);
num = (num * 8) + (ch & 0xF);
}
}
else
{
while(ch = *buffer++)
{
if((ch < '0') || (ch > '9'))
return(FALSE);
num = (num * 10) + (ch & 0xF);
}
}
}
}
*value = num * neg;
return(TRUE);
}
#endif